function refreshPosition() {
	if(navigator && navigator.geolocation){
		navigator.geolocation.getCurrentPosition(geoSuccess, geoFailure);
	}
}

var currentPosition;
function geoSuccess(position) {
	currentPosition = position;
}
function geoFailure(errData) {
}

qype.init = function () {
	if(util.width() == 320) $('body').addClass('w320');
	
	// create a carousel widget to contain the views
	var content = SwitcherWidget();
	$("#content").append(content.getHtml());

	// create containers for the views in the carousel
	content.addView(qype.views.locationView.getHtml());
	content.addView(qype.views.placesView.getHtml());
	content.addView(qype.views.placeView.getHtml());

	// initialize widgets in the views
	qype.views.locationView.init(function(location, title) {
	    widget.preferences.setItem("location", location || "");
	    widget.preferences.setItem("location-title", title || "");
		refreshLocation();
		if(getLocation() == "CURRENT_LOCATION") refreshPosition();
	});
	qype.views.placesView.init();
	qype.views.placeView.init();
	
	// create links for navigating between the views
	var links = {
		location: qype.views.locationView.showMwl(true) + content.linkMwl(0),
		backToLocation: qype.views.locationView.showMwl(false) + content.linkMwl(0),
		places: qype.views.placesView.showMwl(true) + content.linkMwl(1),
		backToPlaces: qype.views.placesView.showMwl(false) + content.linkMwl(1),
		place: qype.views.placeView.showMwl(true) + content.linkMwl(2)
	};

	// initialize quick link to the location view
	$("#banner").html(sprintf('<div onclick="%s">&nbsp;</div>', links.location));

	// initialize links in the views
	qype.views.locationView.setLinks(links);
	qype.views.placesView.setLinks(links);
	qype.views.placeView.setLinks(links);

	// initialize data in the views
	qype.views.locationView.populateQuickList();
	qype.views.placesView.loadCategories();

	refreshLocation();
	
	content.showView(0);
	qype.views.locationView.show(true);
	
	
	function refreshLocation() {
		if (getLocation()) {
			qype.views.placesView.setLocation(getLocation(), getLocationTitle());
		}
	}
	
	function getLocation() {
		return widget.preferences.getItem("location") || "";
	}
	
	function getLocationTitle() {
		return widget.preferences.getItem("location-title") || "";
	}
	
	//refreshPosition();
};
